package com.aidex.biz.service.impl;

import com.aidex.biz.service.SmSSendService;
import com.aidex.common.utils.http.HttpUtils;
import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAConfig;
import com.wechat.pay.java.service.certificate.CertificateService;
import org.springframework.stereotype.Service;

import java.nio.charset.StandardCharsets;
import java.security.cert.X509Certificate;
import java.util.List;

/**
 * 微信商户支付信息Service业务层处理
 *
 * @author sean
 * @email 2074844820@qq.com
 * @date 2022-09-21
 */
@Service
public class SmSSendServiceImpl implements SmSSendService {
    private String username = "yexufeng";
    private String password = "19851018";

    public void paytoend() {
        String merchantId = "1500342932";
        String merchantSerialNumber = "547FE2964B07C2B0FA56D22EB8C10B167266C83D";
        String apiV3Key = "21232f297a57a5a743894a0e4a801fc2";
        String privateKeyPath = "";
        /** 微信支付平台证书路径 */
        String wechatPayCertificatePath = "";
        Config config =
                new RSAConfig.Builder().merchantId(merchantId).privateKeyFromPath(privateKeyPath).merchantSerialNumber(merchantSerialNumber).wechatPayCertificatesFromPath(wechatPayCertificatePath).build();
        CertificateService certificateService = new CertificateService.Builder().config(config).build();
        List<X509Certificate> certificates =
                certificateService.downloadCertificate(apiV3Key.getBytes(StandardCharsets.UTF_8));
    }


    @Override
    public boolean sendSMS(String username, String key, String phone, String qm, String content) {
        String sendUrl = "https://api.smsbao.com/sms?u=USERNAME&p=PASSWORD&m=PHONE&c=CONTENT";
        sendUrl = sendUrl.replace("USERNAME", username).replace("PASSWORD", key).replace("PHONE", phone).replace(
                "CONTENT", "【" + qm + "】" + content);
        String result = HttpUtils.sendGet(sendUrl);
        if ("0".equals(result)) {
            return true;
        } else {
            return false;
        }
    }

    public static void main(String[] args) {
        String sendUrl = "https://api.smsbao.com/sms?u=USERNAME&p=PASSWORD&m=PHONE&c=CONTENT";
        sendUrl =
                sendUrl.replace("USERNAME", "yexufeng").replace("PASSWORD", "ff22d7058cc14283a5bae2023dbaba31").replace("PHONE", "17771704470").replace("CONTENT", "测试");
        String result = HttpUtils.sendGet(sendUrl);
        System.out.println(result);
    }
}
